import { createRouter, createWebHistory } from 'vue-router'

const routes = [
    // 登录页面 - 白名单页面，无需权限验证
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login/Index.vue'),
        meta: { 
            title: '登录',
            access: 'white'
        }
    },
    // 白名单页面 - 错误、权限、路由异常页面
    {
        path: '/error',
        name: 'Error',
        component: () => import('@/components/common/SystemError.vue'),
        meta: { 
            title: '系统错误',
            access: 'white'
        }
    },
    {
        path: '/permission',
        name: 'Permission',
        component: () => import('@/components/common/NoPermission.vue'),
        meta: { 
            title: '权限不足',
            access: 'white'
        }
    },
    {
        path: '/route-error',
        name: 'RouteError',
        component: () => import('@/components/common/RouteNotFound.vue'),
        meta: { 
            title: '页面不存在',
            access: 'white'
        }
    },
    // 404页面 - 必须放在最后
    {
        path: '/:pathMatch(.*)*',
        redirect: '/route-error'
    },
    // 主布局 - 包含左侧菜单和右侧内容区域
    {
        path: '/',
        name: 'Main',
        component: () => import('@/views/home/Index.vue'),
        meta: { 
            title: '传奇管理系统', 
            icon: 'House',
            access: 'login'
        },
        children: [
            // 仪表盘 - 默认显示页面
            {
                path: '',
                name: 'Dashboard',
                component: () => import('@/views/home/Dashboard.vue'),
                meta: {
                    title: '仪表盘',
                    icon: 'Monitor',
                    access: 'login'
                }
            },
            // 系统管理模块
            {
                path: 'system/user',
                name: 'SystemUser',
                component: () => import('@/views/system/user/Index.vue'),
                meta: {
                    title: '用户管理',
                    icon: 'User',
                    access: 'permission',
                    permission: 'SYSTEM_USER'
                }
            },
            {
                path: 'system/role',
                name: 'SystemRole',
                component: () => import('@/views/system/role/Index.vue'),
                meta: {
                    title: '角色管理',
                    icon: 'UserFilled',
                    type: 1, // 1: dialog模式，0或不存在: tabs模式
                    access: 'permission',
                    permission: 'SYSTEM_ROLE'
                }
            },
            {
                path: 'system/role-tabs',
                name: 'SystemRoleTabs',
                component: () => import('@/views/system/role/Index.vue'),
                meta: {
                    title: '角色管理(Tabs)',
                    icon: 'UserFilled',
                    type: 0, // 0或不存在: tabs模式
                    access: 'permission',
                    permission: 'SYSTEM_ROLE'
                }
            },
            {
                path: 'system/menu',
                name: 'SystemMenu',
                component: () => import('@/views/system/menu/Index.vue'),
                meta: {
                    title: '菜单管理',
                    icon: 'Menu',
                    access: 'permission',
                    permission: 'SYSTEM_MENU'
                }
            },
            {
                path: 'system/auth',
                name: 'SystemAuth',
                component: () => import('@/views/system/auth/Index.vue'),
                meta: {
                    title: '权限管理',
                    icon: 'Key',
                    access: 'permission',
                    permission: 'SYSTEM_AUTH'
                }
            },
            {
                path: 'system/branch',
                name: 'SystemBranch',
                component: () => import('@/views/system/branch/Index.vue'),
                meta: {
                    title: '分支管理',
                    icon: 'Connection',
                    access: 'permission',
                    permission: 'SYSTEM_BRANCH'
                }
            },
            {
                path: 'system/module',
                name: 'SystemModule',
                component: () => import('@/views/system/module/Index.vue'),
                meta: {
                    title: '模块管理',
                    icon: 'Grid',
                    access: 'permission',
                    permission: 'SYSTEM_MODULE'
                }
            },
            {
                path: 'system/token',
                name: 'SystemToken',
                component: () => import('@/views/system/token/Index.vue'),
                meta: {
                    title: '令牌管理',
                    icon: 'Key',
                    access: 'permission',
                    permission: 'SYSTEM_TOKEN'
                }
            },
            {
                path: 'system/record',
                name: 'SystemRecord',
                component: () => import('@/views/system/record/Index.vue'),
                meta: {
                    title: '记录管理',
                    icon: 'Document',
                    access: 'permission',
                    permission: 'SYSTEM_RECORD'
                }
            },
            {
                path: 'system/verify',
                name: 'SystemVerify',
                component: () => import('@/views/system/verify/Index.vue'),
                meta: {
                    title: '验证管理',
                    icon: 'Checked',
                    access: 'permission',
                    permission: 'SYSTEM_VERIFY'
                }
            },
            {
                path: 'system/summary',
                name: 'SystemSummary',
                component: () => import('@/views/system/summary/Index.vue'),
                meta: {
                    title: '系统概览',
                    icon: 'DataBoard',
                    access: 'permission',
                    permission: 'SYSTEM_SUMMARY'
                }
            },
            // 投票管理模块
            {
                path: 'vote/list',
                name: 'VoteList',
                component: () => import('@/views/vote/list/Index.vue'),
                meta: {
                    title: '投票列表',
                    icon: 'List',
                    access: 'login'
                }
            },
            {
                path: 'vote/record',
                name: 'VoteRecord',
                component: () => import('@/views/vote/record/Index.vue'),
                meta: {
                    title: '投票记录',
                    icon: 'Document',
                    access: 'login'
                }
            },
            {
                path: 'vote/user',
                name: 'VoteUser',
                component: () => import('@/views/vote/user/Index.vue'),
                meta: {
                    title: '投票用户',
                    icon: 'User',
                    access: 'login'
                }
            },
            {
                path: 'vote/entry',
                name: 'VoteEntry',
                component: () => import('@/views/vote/entry/Index.vue'),
                meta: {
                    title: '投票项管理',
                    icon: 'Plus',
                    access: 'login'
                }
            },
            {
                path: 'vote/extra',
                name: 'VoteExtra',
                component: () => import('@/views/vote/extra/Index.vue'),
                meta: {
                    title: '投票额外设置',
                    icon: 'Setting',
                    access: 'login'
                }
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router
